package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.*;
import cn.gson.boot.model.service.WenDaService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/wenda")
public class WenDaController {
    @Autowired
    WenDaService wenDaService;

    //查询所有问答（根据问题模糊查询）
    @RequestMapping("/selecAllWenDa")
    @ResponseBody
    public Map<String,Object> selecAllWenDa(String wenti, Integer pageNumm, Integer pageSizee){
        Page<Object> objects = PageHelper.startPage(pageNumm, pageSizee);
        List<Wenda> list =  wenDaService.selecAllWenDa(wenti);;
        Map<String,Object> map = new HashMap();
        map.put("total", objects.getTotal());
        map.put("list", list);
        return map;
    }

    //新增问答
    @RequestMapping("/addWenDa")
    @ResponseBody
    public void addWenDa(@RequestBody Wenda wenda){
       wenDaService.addWenDa(wenda);
    }

    //移除问答
    @RequestMapping("/yichuWenDa")
    @ResponseBody
    public void yichuWenDa(Integer wdId){
        wenDaService.yichuWenDa(wdId);
    }
}
